<template>
    <div>
        <el-form label-width="80px" :model="form">
            <el-form-item label="学号">
                <el-input v-model="form.studentId" style="width:200px"></el-input>
            </el-form-item>
            <el-form-item label="姓名">
                <el-input v-model="form.userName" style="width:200px"></el-input>
            </el-form-item>
            <!-- <div slot="footer" class="dialog-footer"> -->
                <el-button type="primary" @click="update()">确认</el-button>
            <!-- </div> -->
        </el-form>
    </div>
</template>

<<script>
export default {
  data() {
      return {
          form: {
          }
      }
  }, 
  mounted() {
      this.getUserInfo()
  },
  methods: {
      getUserInfo() {
          var self = this
          this.$http.get('/user/getById',{}).then(({body}) => {
          console.log(body);
          if (body.success === true) {
            self.form = body.data
          } else {
            window.location.href = '/login.html';
          }
        });
      },
      update() {
        this.$http.post("/user/save?", this.form, {}).then(({body}) => {
            if (body.success === true) {
                this.getUserInfo();
                this.$message.success(body.message);
                // window.location.reload();
            } else {
                this.$message.error(body.message);
            }
        }).catch(() => {
            this.$message.error('修改失败');
        })
      }
  },
}
</script>
